from django import http
from django.shortcuts import render
from rest_framework.views import APIView
from rest_framework.response import Response
from apps.verifications.libs.captcha.captcha import captcha
from django_redis import get_redis_connection


# Create your views here.
class ImageCodeView(APIView):
    def get(self,request,uuid):
        redis_conn = get_redis_connection("verify_code")

        text, img_byte = captcha.generate_captcha()

        redis_conn.setex(f"img_{uuid}", 300, text) # key,过期时间，value

        # 响应图形验证码: image/jpg
        return http.HttpResponse(img_byte, content_type='image/jpg')
